using DotNetCommon.Expressions.Base;
using DotNetCommon.Extensions;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;

namespace DotNetCommon.Expressions.Visit
{
    /// <summary>
    /// 示例: arr.Length
    /// </summary>
    internal class ArrayLengthVisit : UnaryVisit
    {
        protected override void Prepare(ExpressionNode node)
        {
            var arrLengthExpression = node.Expression as UnaryExpression;
            node.Children.Add(new ExpressionNode
            {
                Parent = node,
                Children = new List<ExpressionNode>(),
                Expression = arrLengthExpression.Operand
            });
        }

        protected override string GenerateFullMarkString(ExpressionNode node)
        {
            var arrLengthExpression = node.Expression as UnaryExpression;
            return $"{arrLengthExpression.Type.GetClassFullName()}.Length";
        }
    }
}
